// 2873. 有序三元组中的最大值 I
// AC: https://leetcode.cn/problems/maximum-value-of-an-ordered-triplet-i/submissions/618255921/

class Solution {
public:
    long long maximumTripletValue(vector<int>& nums) {
        long long ans=0;
        int n=nums.size();
        vector<int> res(n,0);
        res[n-1]=nums[n-1];
        for(int i=n-2;i>=0;--i)
            res[i]=max(res[i+1],nums[i]);
        for(int i=0;i<n-2;++i){
            for(int j=i+1;j<n-1;++j){
                ans=max(ans,(long long)(nums[i]-nums[j])*res[j+1]);
            }
        }
        return ans;
    }
};